﻿using Newtonsoft.Json;
using Omabar.BLL;
using Omabar.Common;
using Omabar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace Omabar.CMS.Handler
{
    /// <summary>
    /// UserAdd 的摘要说明
    /// </summary>
    public class UserEdit : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            RESP_Info info = new RESP_Info();
            try
            {
                context.Response.ContentType = "text/plain";
                string USER_ID = context.Request["USER_ID"];
                string USER_NAME = context.Request["USER_NAME"];
                string USER_NIKENAME = context.Request["USER_NIKENAME"];
                string EMAIL = context.Request["EMAIL"];
                string TELEPHONE = context.Request["TELEPHONE"];
                string ENABLE = string.IsNullOrEmpty(context.Request["ENABLE"]) ? "0" : context.Request["ENABLE"];
                string PASSWORD = context.Request["PASSWORD"];
                USER hotel = new USER()
                {
                    USER_ID = USER_ID,
                    USER_NAME = USER_NAME,
                    USER_NIKENAME = USER_NIKENAME,
                    TELEPHONE = TELEPHONE,
                    EMAIL = EMAIL,
                    ENABLE = short.Parse(ENABLE),
                    PASSWORD = PASSWORD,
                    USER_HEAD_IMG = AppConst.Domain + "Images / cover_default.jpg"
                };

                User_BLL bll = new User_BLL();
                info = bll.Update(hotel);
            }
            catch (Exception ex)
            {
                Tom.Net.Log.LogManager.Error("编辑用户失败", ex);
                info.Success = false;
                info.Title = "错误";
                info.Tip = "<h5><p>编辑用户失败</p></h5>";
                info.Url = "UserList.aspx";
            }

            context.Response.Write(JsonConvert.SerializeObject(info));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}